package com.xuelang.pipeline.domain.task.service.impl;

import com.xuelang.pipeline.client.common.exception.BizException;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.task.dto.TaskDefQuery;
import com.xuelang.pipeline.domain.task.TaskDef;
import com.xuelang.pipeline.domain.task.repository.TaskDefRepository;
import com.xuelang.pipeline.domain.task.service.TaskDefDomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 流水线任务定义领域服务实现类
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
@Service
public class TaskDefDomainServiceImpl implements TaskDefDomainService {

    @Autowired
    private TaskDefRepository taskDefRepository;

    @Override
    public PageRecord<TaskDef> pageList(long currentPage, long pageSize, TaskDefQuery taskDefQuery) {
        return taskDefRepository.pageList(currentPage, pageSize, taskDefQuery);
    }

    @Override
    public List<TaskDef> list(TaskDefQuery taskDefQuery) {
        return taskDefRepository.list(taskDefQuery);
    }

    @Override
    public Boolean save(TaskDef taskDef) {
        if(existsCode(taskDef.getRefTag())) {
            throw new BizException("refTag已经存在");
        }
        if(existsName(taskDef.getName())) {
            throw new BizException("name已经存在");
        }
        return taskDefRepository.save(taskDef);
    }

    @Override
    public Boolean update(TaskDef taskDef) {
        return taskDefRepository.update(taskDef);
    }

    @Override
    public Boolean delete(String uuid) {
        return taskDefRepository.delete(uuid);
    }

    @Override
    public TaskDef query(String uuid) {
        return taskDefRepository.query(uuid);
    }

    @Override
    public Boolean existsCode(String refTag) {
        return taskDefRepository.existsCode(refTag);
    }

    @Override
    public Boolean existsName(String taskDefName) {
        return taskDefRepository.existsName(taskDefName);
    }
}
